<template>
	<view>
		<view class="uni-input-wrapper">
			<uni-icons type="person" size="25" />
			<input v-model="phone" class="uni-input" type="number" focus placeholder="请输入手机号码/用户名" />
		</view>
		<view class="uni-input-wrapper">
			<uni-icons type="locked" size="25" />
			<input v-model="passwd" class="uni-input" :password="showPassword" type="text" placeholder="请输入密码" />
			<uni-icons class="eyes" type="eye-filled" :color="!showPassword?'#007AFF':''" size="20" @click="changePassword"></uni-icons>
		</view>
		<button type="primary" class="submitBtn" @click="login">登 录</button>
	</view>
</template>

<script>
	import {
		uniIcons
	} from '@dcloudio/uni-ui'
	import kddes from '@/util/base/kjax.des.js';
	export default {
		data() {
			return {
				showPassword: true,
				phone: '',
				passwd: '',
				callBackUrl: null,
			};
		},
		components: {
			uniIcons
		},
		onLoad(params) {
			console.log(params)
			const {
				callBackUrl = null
			} = params;
			this.callBackUrl = callBackUrl;
		},
		methods: {
			changePassword() {
				this.showPassword = !this.showPassword;
				console.log(this.showPassword)
			},
			login() {
				if (!this.phone) {
					return uni.showToast({
						icon: 'none',
						title: "手机号不能为空",
					});
				}
				if (!this.passwd) {
					return uni.showToast({
						icon: 'none',
						title: "密码不能为空",
					});
				}
				let params = {
					loginname: this.phone,
					password: kddes.getDes(this.passwd),
					isoperator: '0',
					inverstortype: '0',
					loginFromWay: '0',
					ip: '127.0.0.1',
				}
				console.log(params)
				this.$http.login("kingdom.kfat.get_cust_login_app", "V2.0", params).then(data => {
					console.log(data)
					if (data.flag === '1') {
						uni.showToast({
							title: '登录成功',
						});
						const path = this.callBackUrl ? '/' + this.callBackUrl : '/pages/index/index';
						console.log(path)
						uni.setStorageSync('userphone', this.phone);
						uni.reLaunch({
							url: path
						});
					} else {
						uni.showToast({
							icon: 'none',
							title: data.msg,
						});
					}
				}).catch(err => {
					console.log(err)

				})
			}
		}
	}
</script>

<style scoped>
	.eyes {
		padding: 10rpx;
	}

	.uni-input {
		background-color: #FFFFFF;
		height: 90rpx;
		line-height: 90rpx;
		font-size: 30rpx;
		flex: 1;
		margin-left: 20rpx;
	}

	.uni-input-wrapper {
		width: 100%;
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: center;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin-bottom: 10rpx;
	}

	.submitBtn {
		background-color: #FF5036;
		margin: 40rpx 20rpx;
	}
</style>
